package com.hqyj.springboot.springboot_multiple_payment.handler;

import com.hqyj.springboot.springboot_multiple_payment.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.Order;
import pojo.RestfulEntity;

@Controller
public class PaymentHandler {

    @Autowired
    @Qualifier("paymentService")
    private PaymentService paymentService;

    @PostMapping(value = "add")
    public @ResponseBody RestfulEntity append(@RequestBody Order order) {
        boolean appendPayment = paymentService.appendPayment(order);
        RestfulEntity restfulEntity = new RestfulEntity();
        if (appendPayment) {
            restfulEntity.setCode(200);
        }else {
            restfulEntity.setCode(201);
        }
        return restfulEntity;
    }
}
